<template>
	<view>
		<image class="bgImage" src="http://cdn.yic3.cn/lawyer/mp-xhs/guide/guideBg.png"></image>
		<image class="logo" src="http://cdn.yic3.cn/lawyer/mp-xhs/guide/guideLogo.png" mode="widthFix"></image>
	</view>
</template>

<script>
	export default {
		data() {
			return {

			};
		},
		onLoad() {
			let that = this
			this.$nextTick(async () => {
				uni.getSystemInfo({
					async success(res) {
						uni.setStorageSync('saveAllList', res)
						await that.launch()
						if (!uni.getStorageSync('sessionKey')) {
							that.getSession()
						}
						that.nextTo()
					},
				})
			})
		},
		methods: {
			nextTo() {
				if (!uni.getStorageSync('guideIsOver') && uni.getStorageSync('config')['client.guide.enable']) {
					uni.reLaunch({
						url: '/pages/guide/guide_2/guide_2'
					})
				} else {
					uni.reLaunch({
						url: '/pages/index/home/home'
					})
				}
			},
			// 是否有sess
			getSession() {
				let that = this
				uni.login({
					complete(res) {
						that.$api.getSession({
							code: res.code
						}).then(res => {
							console.log(res);
							if (res.data.code == 0) {
								uni.setStorageSync('sessionKey', res.data.data)
								uni.getUserInfo({
									complete(res) {
										console.log(res);
										that.$api.phonelogin({
											loginType: 'wxapplet',
											wxapplet: {
												"iv": res.iv,
												"sessionKey": uni
													.getStorageSync(
														'sessionKey'),
												"encryptedData": res
													.encryptedData
											}
										}).then(e => {
											if (e.data.code == 0) {
												uni.setStorageSync('Token',
													e.data.data.token)
											}
										})
									}
								})
							}
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.bgImage {
		position: absolute;
		left: 0;
		right: 0;
		top: 0;
		width: 100%;
		display: block;
		height: 100vh;
	}

	.logo {
		position: fixed;
		top: 0;
		bottom: 0;
		left: 0;
		right: 0;
		margin: auto;
		width: 388rpx;
		height: 140rpx;
		z-index: 11;
	}
</style>